package com.example.yunmo;
//对话框92

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import com.google.android.material.navigation.NavigationView;

public class FirstActivity extends AppCompatActivity implements View.OnClickListener,NavigationView.OnNavigationItemSelectedListener{
    private EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        System.out.println("hello");
        setContentView(R.layout.main_layout);
        ((Button)findViewById(R.id.course_button)).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(FirstActivity.this,"you clicked 课表",Toast.LENGTH_SHORT).show();
                        startActivity(new Intent(FirstActivity.this,kebiao.class));
                    }
                });
//        Button button=(Button) findViewById(R.id.button);
//        Button button3=(Button) findViewById(R.id.button3);
//        button.setOnClickListener(this);
//        button3.setOnClickListener(this);
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
//        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
//        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
//                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
//        drawer.addDrawerListener(toggle);
//        toggle.syncState();
//        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
//        navigationView.setNavigationItemSelectedListener(this);
    }
        @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        //FirstActivity.this
        switch (item.getItemId())
        {
            case R.id.nav_change:
                startActivity(new Intent(this, ChooseClassActivity.class));
                break;
            case R.id.nav_add:
                startActivity(new Intent(this, AddCourseActivity.class));
                break;
            case R.id.nav_refresh:
                startActivity(new Intent(this, ChangeCourseActivity.class));
                break;
            case R.id.nav_about:
                startActivity(new Intent(this, AboutActivity.class));
                break;
            case R.id.nav_contact:
                startActivity(new Intent(this, ContactActivity.class));
                break;
        }
        ((DrawerLayout)findViewById(R.id.drawer_layout)).closeDrawer(GravityCompat.START);
        return true;
    }
//    long startime=0;
    @Override
    public void onBackPressed(){
//        long currenttime=System.currentTimeMillis();
//        if((currenttime-startime)>=2000){
//            Toast.makeText(FirstActivity.this,"再按一次退出",Toast.LENGTH_SHORT).show();
//            startime=currenttime;
//        }else{
//            finish();
//        }
        AlertDialog.Builder dialog=new AlertDialog.Builder(FirstActivity.this);
        dialog.setTitle("警告");
        dialog.setMessage("确认退出吗？");
        dialog.setCancelable(true);
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        });
       dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialogInterface, int i) {
           }
       }) ;
       dialog.show();
    }
    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.button3:
                editText=(EditText)findViewById(R.id.edit_text);//获取搜索框的内容
                String inputText=editText.getText().toString();
                Toast.makeText(this,inputText,Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
